#include "AwardEquipDialog.h"
#include "model/proxy/ItemProxy.h"
#include "net/NetController.h"

AwardEquipDialog::AwardEquipDialog(void)
	:mName(NULL),mDesc(NULL),mEquipDetail(NULL)
{
}

AwardEquipDialog::~AwardEquipDialog(void)
{
	CC_SAFE_RELEASE(mName);
	CC_SAFE_RELEASE(mDesc);
}

bool AwardEquipDialog::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mName", CCLabelTTF *, this->mName);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mDesc", CCLabelTTF *, this->mDesc);
	return false;
}

SEL_MenuHandler AwardEquipDialog::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "onDoItClick", AwardEquipDialog::onDoItClick);
	return NULL;
}

SEL_CCControlHandler AwardEquipDialog::onResolveCCBCCControlSelector( CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onSellBtnClick", AwardEquipDialog::onSellBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onMeltBtnClick", AwardEquipDialog::onMeltBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCloseBtnClick", AwardEquipDialog::onCloseBtnClick);
	return NULL;
}

void AwardEquipDialog::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{
	mEquipDetail = EquipDetail::create(this);
	mEquipDetail->setPosition(6, 156);
	mEquipDetail->mEquipIcon->setPosition(ccp(13, 56));
	addChild(mEquipDetail);
}

void AwardEquipDialog::onEnter()
{
	CCNode::onEnter();
}

void AwardEquipDialog::onExit()
{
	CCNode::onExit();
}

bool AwardEquipDialog::init()
{
	return true;
}

void AwardEquipDialog::refresh()
{
	EquipInfo* equipInfo = (EquipInfo*)mData;
	mEquipDetail->setData(equipInfo);
	mEquipDetail->refresh();
}

void AwardEquipDialog::_onNotification( CCObject* object )
{
	
}

void AwardEquipDialog::onDoItClick(CCObject* pSender)
{
    
}

void AwardEquipDialog::onSellBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	EquipInfo* equipInfo = (EquipInfo*)mData;
	vector<int>& sellList = ItemProxy::getSingletonPtr()->sellList;
	sellList.clear();
	sellList.push_back(equipInfo->index);
	NetController::getSingletonPtr()->sellEquipage(sellList);
}

void AwardEquipDialog::onMeltBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	EquipInfo* equipInfo = (EquipInfo*)mData;
	ItemProxy::getSingletonPtr()->mSelectList.clear();
	ItemProxy::getSingletonPtr()->mSelectList.push_back(equipInfo->index);
	Framework::getSingletonPtr()->popup("MeltOkDialog", equipInfo);
}

void AwardEquipDialog::onCloseBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	close();
}
